#!/usr/bin/env python3

# -*- coding: utf-8 -*-

import argparse
import datetime
import os
import pprint
import random
import re
import shlex
import subprocess
import signal
import sys
import time
import shutil
import json
import time
repo_root_dir="/home/zjh/.vs/wa-iot-edge-sdk"

sys.path.append(repo_root_dir + "/deps/CoAPthon3/coapthon")
from coapthon.client.helperclient import HelperClient
from coapthon import defines
if __name__ == "__main__":

    device_id="123";

    wa_client = HelperClient(server=("127.0.0.1", 5683))

    # WRITE 3 REG from 120, but PLC APP will interpreter it as BOOL
    path = "/snap7?DI={}&Area=MK&Start=11&DBNumber=0&Datatype=Double".format(device_id)
   
    value = [3.1111]
    wa_client.put(path, (defines.Content_types["application/json"],json.dumps(value)))
    response2 = wa_client.get(path)
    # print(str(response2.payload))
    j_result = json.loads(response2.payload)
    if (j_result != value):
        print ("error.")
        sys.exit(1)
    print("Snap7 #1: Ok")